#include <bits/stdc++.h>
using namespace std;

struct sp
{
	int d;
	int v;
	int a;
	int spe;
	bool chaosu;
	int ne;
}car[100010];

int det[100010];

bool cmp(sp a,sp b)
{
	return a.d>b.d;
}

int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int T;
	int n,m,len,vmax;
	int i;
	
	
	int tmp,xe,vpow;
	cin>>T;
	for(int ijk=1;ijk<=T;ijk++)
	{
		cin>>n>>m>>len>>vmax;
		for(i=1;i<=n;i++)
		{
			cin>>car[i].d>>car[i].v>>car[i].a;
			if(car[i].a>0)
				car[i].spe=1;
			else
				if(car[i].a==0)
					car[i].spe=0;
				else
					car[i].spe=-1;
			car[i].chaosu=false;
		}
		for(i=1;i<=m;i++)
			cin>>det[i];
		
		int ans1=0,ans2=1;
		for(i=1;i<=n;i++)
		{
			if(car[i].spe==1)
			{
				if(car[i].d<=det[m])
				{
					xe=det[m]-car[i].d;
					vpow=car[i].v*car[i].v+2*car[i].a*xe;
					if(vpow>vmax*vmax)
					{
						car[i].chaosu=true;
						ans1++;
					}
				}
			}
			else
			{
				if(car[i].spe==0)
				{
					if(car[i].d<=det[m])
					{
						if(car[i].v>vmax)
						{
							car[i].chaosu=true;
							ans1++;
						}
					}
				}
				else
				{
					if(car[i].d<=det[m])
					{
						tmp=lower_bound(det+1,det+m+1,car[i].d)-det;
						xe=det[tmp]-car[i].d;
						vpow=car[i].v*car[i].v+2*car[i].a*xe;
						if(vpow>vmax*vmax)
						{
							car[i].ne=tmp;
							car[i].chaosu=true;
							ans1++;
						}
					}
				}
			}
		}
//		cout<<ans1<<endl;
		bool y=true;
		for(i=1;i<=n;i++)
			if(car[i].chaosu==true)
				y=false;
		if(y==true)
		{
			ans2=0;
			ans2=m-ans2;
			cout<<ans1<<" "<<ans2<<endl;
			continue;
		}
		
		
		int temp=m;
		sort(car+1,car+n+1,cmp);
		for(i=1;i<=n;i++)
		{
			if(car[i].chaosu==false)
				continue;
			if(car[i].spe>=0)
				continue;
			
			temp=car[i].ne;
			break;
		}
		
		for(i=1;i<=n;i++)
		{
			if(car[i].chaosu==false)
				continue;
			if(car[i].spe<0)
				continue;
			
			if(car[i].d>det[temp])
			{
				temp=m;
				break;
			}
			
			if(car[i].spe==0)
				continue;
			
			
			int xxe=det[temp]-car[i].d;
			int vvpow=car[i].v*car[i].v+2*car[i].a*xxe;
			if(vvpow<=vmax*vmax)
			{
				temp=m;
				break;
			}
		}
		
		for(i=1;i<=n;i++)
		{
			if(car[i].chaosu==false)
				continue;
			if(car[i].spe>=0)
				continue;
			
			xe=det[temp]-car[i].d;
			vpow=car[i].v*car[i].v+2*car[i].a*xe;
			if(vpow<=vmax*vmax)
			{
				temp=car[i].ne;
				ans2++;
			}
		}
		ans2=m-ans2;
		cout<<ans1<<" "<<ans2<<endl;
	}
	return 0;
}
